<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.sinba.common.business.service.IMatchService"%>
<%@page import="com.sinba.common.business.entity.Sell"%>
<%@page import="java.util.GregorianCalendar"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.sinba.common.business.dto.SellQueryDTO"%>
<%@page import="com.sinba.common.business.service.ISellService"%>
<%@page import="com.sinba.common.business.dto.BuyQueryDTO"%>
<%@page import="com.sinba.common.business.service.IBuyService"%>
<%@page import="com.sinba.common.business.dto.CombinedPriceStatDTO"%>
<%@page import="com.sinba.common.system.dto.RuleDTO"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="com.sinba.common.utils.TranType"%>
<%@page import="com.sinba.common.user.service.IRegisterUserService"%>
<%@page import="com.sinba.common.user.dto.RegisterUserDTO"%>
<%@page import="com.sinba.common.user.dto.RegisterUserQueryDTO"%>
<%@page import="com.sinba.common.system.dto.SingleGroupReportStatDTO"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="com.sinba.common.system.dto.TransactionRecordDTO"%>
<%@page
	import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@page import="com.sinba.common.news.dto.NewsContentDTO"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.news.dto.NewsQueryDTO"%>
<%@page import="com.sinba.common.news.service.INewsService"%>
<%@page
	import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.sinba.common.business.dto.MatchQueryDTO"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ include file="../language.jsp" %>
<%
	ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	INewsService ns = (INewsService) ac.getBean("newsService");
	NewsQueryDTO queryDTO = new NewsQueryDTO();
	queryDTO.setNewType("WebAffiche");
	queryDTO.setLimit(6);
	PageDTO pagedto = ns.findNewsByCategory(queryDTO);

	NewsContentDTO content = ns
			.findTop1NewsByCategory(new NewsQueryDTO(null, null, null, "NewNotice", null, "WebAffiche"));

	ITransactionRecordService transactionRecordService = (ITransactionRecordService) ac
			.getBean("transactionRecordService");
	Double balance1 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),
			"Dynamic");
	Double balance2 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),
			"Static");
	Double balance3 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),
			"SignIn");
	request.setAttribute("balance1", balance1);
	request.setAttribute("balance2", balance2);
	request.setAttribute("balance3", balance3);
	request.setAttribute("pagedto", pagedto);
	request.setAttribute("content", content);

	NewsQueryDTO queryDTO1 = new NewsQueryDTO();
	queryDTO1.setNewType("WebNews");
	queryDTO1.setLimit(6);
	PageDTO pagedto1 = ns.findNewsByCategory(queryDTO1);
	request.setAttribute("pagedto1", pagedto1);

	IRegisterUserService registerUserService = (IRegisterUserService) ac.getBean("registerUserService");
	RegisterUserQueryDTO qdto = new RegisterUserQueryDTO();
	qdto.setLoginName((String) session.getAttribute("loginName"));
	RegisterUserDTO registerUserDTO = registerUserService.findRegisterUserByIdOrLoginName(qdto);
	request.setAttribute("registerUserDTO", registerUserDTO);
	session.setAttribute("registerUserDTO", registerUserDTO);
	request.setAttribute("levels", RuleDTO.level.get(registerUserDTO.getRegisterLevel()));

	//正在卖出前5条
	ISellService sellService = (ISellService) ac.getBean("sellService");
	/* SellQueryDTO sellQueryDTO = new SellQueryDTO();
	sellQueryDTO.setSearchType("MatchIng");
	sellQueryDTO.setMultipleStatus(new Integer[]{0,1});
	sellQueryDTO.setLimit(5);
	PageDTO sellPageDto = sellService.findSellPage(sellQueryDTO,"desc","id");
	request.setAttribute("sellPageDto",sellPageDto); */

	List<CombinedPriceStatDTO> combinedPriceStatDTOs = new ArrayList<CombinedPriceStatDTO>();
	combinedPriceStatDTOs = sellService.combinedPriceStat();
	request.setAttribute("combinedPriceStat", combinedPriceStatDTOs);

	//正在买入前5条
	IBuyService buyService = (IBuyService) ac.getBean("buyService");
	BuyQueryDTO buyQueryDTO = new BuyQueryDTO();
	buyQueryDTO.setSearchType("MatchIng");
	buyQueryDTO.setMultipleStatus(new Integer[] { 0, 1 });
	buyQueryDTO.setLimit(5);
	PageDTO buyPageDto = buyService.findBuyPage(buyQueryDTO, "desc", "id");
	request.setAttribute("buyPageDto", buyPageDto);
	session.setAttribute("end", "首页");
	session.setAttribute("middle", "首页");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><fmt:message key="i18n.indexShowPage" />-<fmt:message
		key="i18n.title" /></title>
<jsp:include page="common.jsp"></jsp:include>
<script src="../echarts/echarts.min.js"></script>
</head>
<body>
	<!-- head -->
	<jsp:include page="page_head.jsp"></jsp:include>
	<!-- content -->
	<!-- USER PROFILE -->
	<div class="row">
		<div class="col-md-12">
			<!-- BOX -->
			<div class="box border">
				<div class="box-title">
					<h4>
						<i class="fa fa-user"></i><span class="hidden-inline-mobile">
							欢迎：${session.userName}(${session.loginName })&nbsp;&nbsp;
							<c:if test="${session.SIGNIN }"><label style="color:red;">今日已签到</label></c:if>
						</span>
					</h4>
				</div>
				<div class="box-body">
					<div class="tabbable header-tabs user-profile">
						<ul class="nav nav-tabs">
							<li class="active"><a href="#pro_overview" data-toggle="tab"><i
									class="fa fa-dot-circle-o"></i> <span
									class="hidden-inline-mobile">Overview</span></a></li>
						</ul>
						<div class="tab-content">
							<!-- OVERVIEW -->
							<div class="tab-pane fade in active" id="pro_overview">
								<div class="row">
									<!-- PROFILE PIC -->
									<div class="col-md-3">
										<div class="list-group">
											<li class="list-group-item zero-padding"><img alt=""
												class="img-responsive" src="img/tx/${registerUserDTO.registerLevel }.jpg"></li>
											<div class="list-group-item profile-details">
												<p style="vertical-align: middle;height: 35px; text-align: center;font-size: 16px;color: #00b0f0;font-weight: 600;">
												<fmt:message key="${registerUserDTO.registerLevel }" />(${levels })
												</p>
												<p><fmt:message key="i18n.dyAccount"/>：
													<a href="dynamicAccountDetails.jsp" 
													style="cursor: pointer;color:red;font-size: 18px;"><fmt:formatNumber value="${balance1}" pattern="#0.0000"/>
													</a>
												</p>
												<p><fmt:message key="i18n.jtAccount"/>：
													<a href="st2aticAccountDetails.jsp" 
													style="cursor: pointer;color:red;font-size: 18px;"><fmt:formatNumber value="${balance2}" pattern="#0.0000"/>
													</a>
												</p>
												<p>签到红包：
													<a href="st2aticAccountDetails.jsp" 
													style="cursor: pointer;color:red;font-size: 18px;"><fmt:formatNumber value="${balance3}" pattern="#0.0000"/>
													</a>
												</p>
												<%-- <p><fmt:message key="i18n.myLoginName"/>：${email }</p> --%>
												<p><fmt:message key="i18n.regTime"/>： <fmt:formatDate value="${registerUserDTO.registerTime}" pattern="yyyy-MM-dd"/></p>
												<p><fmt:message key="titie.openTime"/>：
													<c:if test="${empty registerUserDTO.activationTime}">
											            <span style="color:red;font-weight: bold;">未激活</span>
											            <span style="color:gray;">（如需激活请联系注册时填写的运营中心）</span>
										            </c:if>
										            <c:if test="${not empty registerUserDTO.activationTime}">
														<fmt:formatDate value="${registerUserDTO.activationTime}" pattern="yyyy-MM-dd"/>
										            </c:if>
										        </p>
											</div>
											
										</div>
									</div>
									<!-- /PROFILE PIC -->
									<!-- PROFILE DETAILS -->
									<div class="col-md-9">
										<!-- ROW 1 -->
										<div class="row">
											<div class="col-md-7 profile-details">
												<h3>推广链接：</h3>
												<div class="row">
													<div class="col-md-12 text-left">
														<div id="pie_1" class="piechart" data-percent="76">
															<span class="percent"></span>
														</div>
														<div class="skill-name"><span style="color:red;" id="recommendUrl1">${basePath}user/register.jsp?recommendUser=${session.loginName }</span></div>
													</div>
												</div>
												<div class="divide-20"></div>
												<!-- BUTTONS -->
												<div class="row">
													<input type="hidden" id="recommendUrl" value="${basePath}user/register.jsp?recommendUser=${session.loginName }" />
													<c:if test="${!session.SIGNIN }">
													<div class="col-md-6">
														<a class="btn btn-danger btn-icon input-block-level"
															href="javascript:void(0);"> <i
															class="fa fa-check-square-o fa-2x"></i>
															<div>今日签到</div>
														</a>
													</div>
													</c:if>
													<div class="col-md-6">
														<a class="btn btn-primary btn-icon input-block-level"
															href="buy.jsp"> <i
															class="fa fa-dollar fa-2x"></i>
															<div><fmt:message key="i18n.aKeyAutoBuy" /></div>
														</a>
													</div>
												</div>
												<!-- /BUTTONS -->
											</div>
											<div class="col-md-5">
												<!-- BOX -->
												<div class="box border inverse">
													<div class="box-title">
														<h4>
															<i class="fa fa-bars"></i><fmt:message key="i18n.noticeBroad"/>
														</h4>
													</div>
													<div class="box-body big sparkline-stats">
														<c:if test="${pagedto.totalSize >0}">
															<c:forEach items="${pagedto.data}" var="data" varStatus="status" >
																<div class="sparkline-row">
																	<span class="title"></span> <span
																		class="value"><a href="news!newsInfo.action?newsQueryDTO.newId=${data.newId}"
																	>${ data.title }</a> </span>
																	<div class="linechart linechart-lg"><a href="news!newsInfo.action?newsQueryDTO.newId=${data.newId}"
																	><fmt:formatDate type="date" value="${data.createTime}" pattern="yyyy-MM-dd" /></a></div>
																</div>
															</c:forEach>
															</c:if>
															<c:if test="${pagedto.totalSize <1 }">
															<div class="sparkline-row">
																	<span class="title"></span> <span
																		class="value"></span>
																	<div class="linechart linechart-lg"><font style="color:red;font-size: 16px;margin-left: 25px;"><fmt:message key="i18n.noNoticeInfoTips"/>!</font></div>
																</div>
															</c:if>
													</div>
												</div>
												<!-- /BOX -->
												<!-- /SAMPLE -->
											</div>
										</div>
										<!-- /ROW 1 -->
										<div class="divide-40"></div>
										<!-- ROW 2 -->
										<div class="row">
											<div class="col-md-12">
												<div class="box border blue">
													<div class="box-title">
														<h4>
															<i class="fa fa-columns"></i> <span
																class="hidden-inline-mobile"><span>当前</span>股价</span>
														</h4>
													</div>
													<div class="box-body">
														<div class="tabbable">
															<ul class="nav nav-tabs">
																<li class="active"><a href="todayPrice"
																	data-toggle="tab"><i class="fa fa-signal"></i> <span
																		class="hidden-inline-mobile"><span>当前</span>股价</span></a></li>
															</ul>
															<div class="tab-content">
																<div class="tab-pane active" id="todayPrice">
																	<table
																		class="table table-striped table-bordered table-hover">
																		<thead>
																			<tr>
																				<th>上次收盘价</th>
																				<th>开盘价</th>
																				<th>当前市场价</th>
																				<th>涨幅(相较0.1)</th>
																				<th>大盘状态</th>
																				<th>今日成交(RMB)</th>
																				<th>今日成交股数(股)</th>
																			</tr>
																		</thead>
																		<tbody>
																			<tr>
																				<td><span id="closingPrice"></span></td>
																				<td id="closingPrice1"></td>
																				<td id="currentPrice"></td>
																				<td id="zhangfu"></td>
																				<td id="marketStatus"></td>
																				<td id="todayClinchMoney"></td>
																				<td id="todayClinchShare"></td>
																			</tr>
																		</tbody>
																	</table>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>
										</div>
										<!-- /ROW 2 -->
										<!-- ROW 3 -->
										<div class="row">
											<div class="col-md-12">
												<div class="box border blue">
													<div class="box-title">
														<h4>
															<i class="fa fa-columns"></i> <span
																class="hidden-inline-mobile"><span>卖出/</span>买入</span>
														</h4>
													</div>
													<div class="box-body">
														<div class="tabbable">
															<ul class="nav nav-tabs">
																<li class="active"><a href="#sales"
																	data-toggle="tab"><i class="fa fa-signal"></i> <span
																		class="hidden-inline-mobile">卖出</span></a></li>
																<li><a href="#feed" data-toggle="tab"><i
																		class="fa fa-rss"></i> <span
																		class="hidden-inline-mobile">买入</span></a></li>
															</ul>
															<div class="tab-content">
																<div class="tab-pane active" id="sales">
																	<table
																		class="table table-striped table-bordered table-hover">
																		<thead>
																			<tr>
																				<th><i class="fa"></i> 卖出价格</th>
																				<th class="hidden-xs"><i
																					class="fa fa-quote-left"></i> 卖出股数</th>
																			</tr>
																		</thead>
																		<tbody>
																			<c:if test="${fn:length(combinedPriceStat) >0}">
																				<c:forEach items="${combinedPriceStat}" var="data" varStatus="status" >
																					<tr>
																						<td align="center">${data.sellPrice}</td>
																						<td align="center">${data.surplusMoney}</td>
																					</tr>
																				</c:forEach>
																				</c:if>
																				<c:if test="${fn:length(combinedPriceStat) <1 }">
																				<tr><td colspan="3"  align="center"><font style="color:red;font-size: 16px;">没有正在挂牌卖出的信息!</font></td></tr>
																				</c:if>
																		</tbody>
																	</table>
																</div>
																<div class="tab-pane" id="feed">
																	<div class="scroller" data-height="250px"
																		data-always-visible="1" data-rail-visible="1">
																		<table
																			class="table table-striped table-bordered table-hover">
																			<thead>
																				<tr>
																					<th><i class="fa fa-user"></i> 买入会员</th>
																					<th class="hidden-xs"><i
																						class="fa fa-dollar"></i> 买入金额</th>
																				</tr>
																			</thead>
																			<tbody>
																				<c:if test="${buyPageDto.totalSize >0}">
																				<c:forEach items="${buyPageDto.data}" var="data" varStatus="status" >
																					<tr>
																						<td align="center">
																							**${fn:substring(data.buyUser,2,-1)}
																						</td>
																						<td align="center">
																							${data.dBuyMoney}
																						</td>
																					</tr>
																				</c:forEach>
																				</c:if>
																				<c:if test="${buyPageDto.totalSize <1 }">
																				<tr><td colspan="2" align="center"><font style="color:red;font-size: 16px;">没有正在排队买入的信息!</font></td></tr>
																				</c:if>
																			</tbody>
																			
																		</table>
																	</div>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>
										</div>
										<!-- /ROW3 -->
										<!-- ROW4 -->
											<div class="row">
												<div class="col-md-12">
													<!-- BOX -->
													<div class="box border blue">
														<div class="box-title">
															<h4><i class="fa fa-signal"></i><span>股价</span>走势图</h4>
														</div>
														<div class="box-body">
															<div style="width:96%;height:400px;margin: 20px;background-color: white;">
															<div id="main" style="width:90%;height:400px;margin: 20px;background-color: white;"></div>
															
															</div>
														</div>
													</div>
												</div>
											</div>
										<!-- /ROW4 -->
									</div>
									<!-- /PROFILE DETAILS -->
								</div>
							</div>
							<!-- /OVERVIEW -->

						</div>
					</div>
					<!-- /content -->
					<!-- foot -->
					<jsp:include page="page_foot.jsp"></jsp:include>
</body>
<script>

$(document).ready(function() {
    //* show all elements & remove preloader
    setTimeout('$("html").removeClass("js")',1000);
    var hours = new Date().getHours();
    var welcome_tip_text = "上午好！";
    if(hours >= 12 && hours < 23){
    	welcome_tip_text = "下午好！";
    }
    $("#welcome_tip_text").text(welcome_tip_text);
    getCurrentSale();
});
function logout(){
	if(confirm("Are you sure you want to quit it(确定退出吗)?")){
		window.top.location.href='logout.jsp';
	}
}

function getCurrentSale(){
	$.post('match!getCurrentSale.action',function(data){
		$('#closingPrice,#closingPrice1').text(data.closingPrice);
		if(data.closingPrice==0){
			$('#closingPrice1').text(0.1);
		}
		$('#todayClinchMoney').text(Math.round(data.todayClinchMoney));
		$('#currentPrice').text(data.currentPrice);
		$('#todayClinchShare').text(data.todayClinchShare);
		$('#zhangfu').text(data.zhangfu+'%');
		$('#marketStatus').text(data.marketStatus.replace('Limit','涨停').replace('Open','开市').replace('Rest','休市'));
	});
} 

function initMyChart(currentPrices,guidePrices,showTimes){
	// 基于准备好的dom，初始化echarts实例
       var myChart = echarts.init(document.getElementById('main'));

       option = {
       	    title: {
       	        text: '股价趋势图',
       	        left: 'center'
       	    },
       	    tooltip: {
       	         trigger: 'axis'
       	    },
       	    legend: {
       	        left: 'left',
       	        data:['市场价','指导价']
       	    },
       	    xAxis: {
       	        type: 'category',
       	        name: '时间',
       	        splitLine: {show: false},
       	        data:showTimes
       	    },
       	    grid: {
       	        left: '3%',
       	        right: '4%',
       	        bottom: '3%',
       	        containLabel: true
       	    },
       	    yAxis: {
       	        type: 'value',
       	        max:0.2
       	    },
       	    series: [
       	        {
       	            name: '市场价',
       	            type: 'line',
       	            data: currentPrices
       	        },
       	        {
       	            name: '指导价',
       	            type: 'line',
       	            data: guidePrices
       	        }
       	    ]
       	};
	
       myChart.setOption(option);
}
$.post('sharePriceTrend!findSharePriceTrend.action',function(data){
 	var currentPrices = new Array;
 	var guidePrices = new Array;
 	var showTimes = new Array;
 	for(var i=0 ;i<data.length;i++){
 		currentPrices[i] = data[i].currentPrice;
 		guidePrices[i] = data[i].guidePrice;
 		showTimes[i] = data[i].showTime;
 	}
 	initMyChart(currentPrices,guidePrices,showTimes);
 });
      
function signIn(loginName){
	$.post('registerUser!userOpt.action?optType=SignIn&loginName='+loginName,function(data){
		$("#signInButton").attr({"disabled":"disabled"});
    	alert(data);
    });
}

    </script>
</html>
